<?php namespace Gdoo\StiReport\Controllers;

use DB;
use Request;
use Validator;

use Gdoo\Index\Controllers\DefaultController;
use Gdoo\Flow\Form;

class StiReportController extends DefaultController
{
    public $permission = ['viewer', 'designer', 'saveReport', 'license', 'render'];

    public function designerAction()
    {
        $template_id = (int)Request::get('template_id');
        $template = DB::table('flow_template')->where('id', $template_id)->first();
        // 报表名称
        $report_name = "{$template['code']}";
        $report_file = '';
        if (is_file(public_path().'/reports/'.$report_name.'.mrt')) {
            $report_file = $report_name;
        }
        return $this->render(['report_name' => $report_name, 'report_file' => $report_file]);
    }

    public function viewerAction()
    {
        return $this->render();
    }

    public function renderAction()
    {
        return $this->render();
    }

    public function saveReportAction()
    {
        $gets = Request::all();
        $fileName = $gets['fileName'];
        file_put_contents(public_path().'/reports/'.$fileName.".mrt", $gets['data']);
        $success = ['success' => true, 'msg' => "保存成功:".$fileName];
        return $success;
    }

    public function licenseAction()
    {
        echo "6vJhGtLLLz2GNviWmUTrhSqnOItdDwjBylQzQcAOiHlrzAZzmWmSnQQ4gKFiZ4LJpJv//QjFVXxcHAVbzZfXjyOGPmj/m+BEjr2Z14dWeqLFNGF74GELbTTKs2+Le/9cDIWdGNnOpEK2aGdYllauMPLQsiScC521JIEYSdOspiRHSLcegksxfNedJjyIjGlfI2YrddBRWGiO+uWOHE5oz9hLG8VPBSRo60KmgkscM5X+7+aQ+6vzKKOC2XB+e6BMQC5qNVBUblfGQR2EjNLZKmSJtvek7IbG/OK+XP0j2bwicyJUGC0pyLHqctr3BpcO/gA5LoVfuwqYG3klL//owBkObPPhJV1HD6XsHL0GDryssJFaDCQIyXMrOn7hNQNkEIyx+AJDNgf5XfxPgEgFsRhYCPYq7ccutg2by8duOxbF3xH0gL/uAQN275COXJBV3W62DSLM+o8azChG+Z7y0dF9f4whZ/SKD4DwNPUWK7osEPVwl5BY+0lkdqd67fatlrlc0QU/ZX9f5QcTKfl5ljuNc+kcqxmd9NND6Xzrw9gFsFqIWqqVo++DdoAZFStXMkOp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